﻿using System.Text.Json;
using DotNetty.Buffers;
using DotNetty.Codecs;
using DotNetty.Transport.Channels;
using FileCommon.Extensions;
using FileCommon.Models;

namespace FileCommon.Codecs;

public class ObjectEncoder : MessageToByteEncoder<UploadFileInfo>
{
    protected override void Encode(IChannelHandlerContext context, UploadFileInfo message, IByteBuffer output)
    {
        var jsonString = JsonSerializer.Serialize(message);
        var bytes = jsonString.GetBytes();
        output.WriteBytes(bytes);
    }
}